package cn.edu.zut.score.controller.admin;

import cn.edu.zut.score.core.domain.PageResponse;
import cn.edu.zut.score.core.domain.RestResponse;
import cn.edu.zut.score.core.dto.request.ClazzPageRequest;
import cn.edu.zut.score.core.dto.response.ClazzResponse;
import cn.edu.zut.score.core.dto.response.UserResponse;
import cn.edu.zut.score.core.entity.Clazz;
import cn.edu.zut.score.service.IClazzService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zby
 * @date 2021/06/27
 */
@RestController
@RequestMapping("/admin/class")
@ApiModel("班级相关api")
@CrossOrigin
public class AdminClassController {
    @Autowired
    private IClazzService iClazzService;

    @ApiOperation("添加班级")
    @PostMapping("")
    public RestResponse<ClazzResponse> addClass(@RequestBody Clazz clazz) {
        return iClazzService.saveClazz(clazz);
    }

    @ApiOperation("根据Id删除班级")
    @DeleteMapping("/{classid}")
    public RestResponse<Long> deleteClass(@PathVariable("classid") Long classid) {
        return iClazzService.deleteClassById(classid);
    }

    @ApiOperation("根据Ids删除班级")
    @DeleteMapping("/list")
    public RestResponse<Integer> deleteClasses(@RequestBody List<Long> allClassIds) {
        return iClazzService.deleteClassByIds(allClassIds);
    }

    @ApiOperation("修改班级")
    @PutMapping("")
    public RestResponse<ClazzResponse> updateClass(@RequestBody Clazz clazz) {
        return iClazzService.saveClazz(clazz);
    }

    @ApiOperation("根据Id查询班级")
    @GetMapping("/{classid}")
    public RestResponse<ClazzResponse> queryClass(@PathVariable("classid") Long classid) {
        return iClazzService.queryClass(classid);
    }

    @ApiOperation("分页查询班级")
    @PostMapping("/list")
    public RestResponse<PageResponse<ClazzResponse>> queryClasses(@RequestBody ClazzPageRequest classQuery) {
        return iClazzService.queryClasses(classQuery);
    }

    @ApiOperation("根据班级ID查询班级学生")
    @GetMapping("/students/{classid}")
    public RestResponse<PageResponse<UserResponse>> queryClassStudents(@PathVariable("classid") Long classid) {
        return iClazzService.queryClassStudents(classid);
    }
}
